const rules = {
  label: [
    { required: true, message: '区域名称不能为空', trigger: 'change' }
  ],
  parentLabel: [
    { required: false, message: '父级区域名称不能为空', trigger: 'change' }
  ],
  type: [
    { required: true, message: '区域类型不能为空', trigger: 'change' }
  ]
}

const params = {
  type: '',
  parentLabel: [],
  label: ''
}

// 迭代获取省市区对应 name
export function transArea(areas, options) {
  let areaCascadeOptions = JSON.parse(JSON.stringify(options))
  let index = -1
  const result = []
  while (index++ < areas.length - 1) {
    const areaId = areas[index]
    areaCascadeOptions.map(({ value, label, children = [] }) => {
      if (value === areaId) {
        result.push({ value, label })
        if (children && children.length) {
          areaCascadeOptions = children
        } else {
          areaCascadeOptions = []
        }
      }
    })
  }
  return result
}

export {
  rules,
  params
}
